package com.huangliusong.dubbo;

import com.alibaba.dubbo.rpc.RpcContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Scanner;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;


/**
 * @author huangliusong
 * @since 2019/1/1
 * {@link }
 */
public class ConsumerClient2 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ClassPathXmlApplicationContext context=new ClassPathXmlApplicationContext("applicationContext-consumer.xml");
        context.start();


        while (true){
            Scanner scanner=new Scanner(System.in);
            String message=scanner.next();
            ServiceAPI serviceAPI=(ServiceAPI)context.getBean("consumer");
            long beginTime=System.currentTimeMillis();
            String send1=serviceAPI.sendMessage(message);
            Future<String> sendFuture=RpcContext.getContext().getFuture();

            long sendEndtime1=System.currentTimeMillis();
            String send2=serviceAPI.sendmessage02(message);
            Future<String> sendFuture2=RpcContext.getContext().getFuture();
            long sendEndtime2=System.currentTimeMillis();
            System.out.println("第一个执行完成："+sendFuture.get()+" "+(sendEndtime1-beginTime));
            System.out.println("第二个执行完成："+sendFuture2.get()+" "+(sendEndtime2-beginTime));
            System.out.println("耗时"+((sendEndtime1-beginTime)+(sendEndtime2-beginTime)));
        }
    }
}
